package com.mlethe.library.utils.view;

import android.widget.LinearLayout;

import androidx.annotation.DrawableRes;
import androidx.core.content.ContextCompat;

import com.google.android.material.tabs.TabLayout;

/**
 * Created by Mlethe on 2018/1/11.
 */
public class TabLayoutUtil {

    /**
     * 添加TabLayout中间分界线
     * @param tabLayout
     * @param drawableId drawable资源id
     * @param padding 内间距
     */
    public static void addMiddleLine(TabLayout tabLayout, @DrawableRes int drawableId, float padding) {
        if (tabLayout != null) {
            LinearLayout linearLayout = (LinearLayout) tabLayout.getChildAt(0);
            linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
            linearLayout.setDividerDrawable(ContextCompat.getDrawable(tabLayout.getContext(), drawableId));
            linearLayout.setDividerPadding((int) padding);
        }
    }
}
